package com.yunchao.test.data.datasource

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.yunchao.test.data.datasource.model.MaintenanceInfoEntityModel
import java.util.Date

@Database(entities = [MaintenanceInfoEntityModel::class], version = 1, exportSchema = false)
@TypeConverters(DateConverter::class)
internal abstract class MaintenanceDatabase : RoomDatabase() {

    abstract fun maintenanceInfoDao(): MaintenanceInfoDao
}


object DateConverter {
    @TypeConverter
    @JvmStatic
    fun fromTimestamp(value: Long?): Date? {
        return value?.let { Date(it) }
    }

    @TypeConverter
    @JvmStatic
    fun dateToTimestamp(date: Date?): Long? {
        return date?.time
    }
}